<template>
    <div>
      <h2>Register</h2>
      <form @submit.prevent="handleRegister">
        <input v-model="username" placeholder="Username" required />
        <input v-model="password" type="password" placeholder="Password" required />
        <button type="submit">Register</button>
      </form>
    </div>
  </template>
  
  <script>
  import { mapActions } from 'vuex';
  
  export default {
    data() {
      return {
        username: '',
        password: ''
      };
    },
    methods: {
      ...mapActions(['register']),
      async handleRegister() {
        await this.register({ username: this.username, password: this.password });
        if (this.$store.state.isAuthenticated) {
          this.$router.push('/info');
        } else {
          alert('Registration failed');
        }
      }
    }
  };
  </script>
  